//
//  BRWalletListCell.m
//  Kexu
//
//  Created by IOS on 2023/7/19.
//

#import "BRWalletListCell.h"

@implementation BRWalletListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setUI];
    }
    return self;
}

- (void)toEdit {
    if (self.editBlock) {
        BOOL isEdit = [self.editBtnTitle.text isEqualToString:Localized(@"wallet_remove")];
        self.editBlock(isEdit);
    }
}


#pragma mark - UI --
- (void)setUI {
    
    self.contentView.backgroundColor = UIColor.whiteColor;
    
    [self.contentView addSubview:self.contView];
    [self.contView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(14);
        make.left.offset(16);
        make.right.offset(-16);
        make.bottom.offset(0);
    }];
    
    UIImage *bubble = UIImageMake(@"pay_cardBG");
    bubble = [bubble resizableImageWithCapInsets:UIEdgeInsetsMake(50, 40, 30, 40) resizingMode:UIImageResizingModeStretch];
    self.bgImg = [[UIImageView alloc] init];
    self.bgImg.image = bubble;
    [self.contView addSubview:self.bgImg];
    [self.bgImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.offset(0);
    }];
    
    UIView *top = [[UIView alloc] init];
    [self.contView addSubview:top];
    [top mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.offset(0);
        make.height.mas_equalTo(44);
    }];
    UIView *bottom = [[UIView alloc] init];
    [self.contView addSubview:bottom];
    [bottom mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.offset(0);
        make.height.mas_equalTo(96);
        make.top.offset(44);
    }];
    
    [top addSubview:self.titleL];
    [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(20);
        make.centerY.offset(0);
    }];
    
    [bottom addSubview:self.textL];
    [self.textL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(20);
        make.centerY.offset(0);
        make.right.offset(-100);
    }];
    
    UIControl *btn = [[UIControl alloc] init];
    btn.layer.cornerRadius = 7;
    btn.layer.masksToBounds = YES;
    btn.layer.borderColor = UIColorWhite.CGColor;
    btn.layer.borderWidth = 0.5;
    [bottom addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(36);
//        make.width.mas_equalTo(78);
        make.centerY.offset(0);
        make.right.offset(-20);
    }];
    [btn addTarget:self action:@selector(toEdit) forControlEvents:UIControlEventTouchUpInside];
    _editBtn = btn;
    
    UIImageView *rImg = [[UIImageView alloc] init];
    rImg.image = UIImageMake(@"arrow_right_white6");
    [btn addSubview:rImg];
    [rImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(10);
        make.width.mas_equalTo(6);
        make.centerY.offset(0);
        make.right.offset(-8);
    }];
    
    QMUILabel *editL = [BRToolsView br_label:Localized(@"wallet_remove") textColor:UIColor.whiteColor font:[UIFont fontS:14]];
    editL.textAlignment = NSTextAlignmentCenter;
    [btn addSubview:editL];
    [editL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.left.offset(10);
        make.right.offset(-20);
        make.width.mas_greaterThanOrEqualTo(48);
    }];
    _editBtnTitle = editL;
}

- (UIView *)contView {
    
    if (_contView == nil) {
        _contView = [[UIView alloc] init];
        _contView.backgroundColor = UIColor.clearColor;
    }
    return _contView;
}

- (QMUILabel *)titleL {
    
    if (_titleL == nil) {
        _titleL = [BRToolsView br_label:@"--" textColor:UIColor.whiteColor font:[UIFont fontS:14]];
        
    }
    return _titleL;
}

- (QMUILabel *)textL {
    if (_textL == nil) {
        _textL = [BRToolsView br_label:@"--" textColor:UIColor.whiteColor font:[UIFont fontS:20]];
        _textL.numberOfLines = 0;
    }
    return _textL;
}

@end
